package yxy.game.pm2.bean.db.newDao;

import yxy.apple.db.DbManager;
import yxy.game.pm2.bean.db.po.TipPo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author James
 * @date 2022/1/23 10:03
 **/
public class TipDAO {
    private static final String
            REPLACE_ONE = "replace into `tip` (`pCode`, `dataId`, `status`) values (?,?,?)",
            SELECT_ALL = "select * from `tip` where `pCode` = ?";

    public static List<TipPo> getList(String playerCode) {
        return DbManager.instance().executeQueryObjectList(SELECT_ALL, new Object[]{playerCode}, TipPo.builder);
    }

    public static boolean replace(List<TipPo> tipPoList) {
        List<Object[]> list = new ArrayList<>();
        for (TipPo tipPo : tipPoList) {
            Object[] objects = new Object[]{tipPo.getPlayerCode(),tipPo.getDataId(),tipPo.isStatus()};
            list.add(objects);
        }
        int[] ints = DbManager.instance().executeBatchCommand(REPLACE_ONE, list);
        return ints.length == tipPoList.size();
    }


}
